package com.lq.learningTest.encapsulation;

public class Stack {

    private SuperLink superLink = new SuperLink();
    /**
     * 压栈方法
     * @param item
     * @return
     */
    public boolean push(Integer item){
        if (superLink.add(item)) {
            return true;
        }else return false;
    }

    /**
     * 弹出栈顶，也就是删除链表的最后一个元素，并且返回
     * @return
     */
    public Integer pop(){
        if(empty()){
            return null;
        }
        Integer integer = superLink.get(superLink.size());
        superLink.remove(superLink.size());
        return integer;
    }

    /**
     * 返回栈顶元素，不弹栈
     * @return
     */
    public Integer peekTop(){
        if(empty()){
            return null;
        }
        return superLink.get(superLink.size());
    }

    /**
     * 返回栈底元素
     * @return
     */
    public Integer peekBottom(){
        if (empty()) {
            return null;
        }
        return superLink.get(1);
    }

    public Integer getIndex(Integer index){
        if (superLink.get(index) != null) {
            return superLink.get(index);
        }else return null;
    }

    /**
     * 放回栈长度
     * @return
     */
    public int size(){
        return superLink.size();
    }

    /**
     * 判断这个队列是否为空
     * @return
     */
    public boolean empty(){
        return size() == 0;
    }
}



